package com.gitee.mars.marsquickframe.controller;

import com.gitee.mars.marsquickframe.request.SysMenuReq;
import com.gitee.mars.marsquickframe.response.result.R;
import com.gitee.mars.marsquickframe.response.vo.SysMenuListVo;
import com.gitee.mars.marsquickframe.service.SysMenuService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制层
 *
 * @Author wq
 * @Date 2020-12-15
 **/
@RestController
@RequestMapping("admin/sysMenu")
@AllArgsConstructor
public class SysMenuController {

    private final SysMenuService sysMenuService;

    /**
     * 新增
     *
     * @param req sysMenu
     */
    @PostMapping("/add")
    public R add(@RequestBody SysMenuReq req) {
        sysMenuService.add(req);
        return R.success("新增成功");
    }

    /**
     * 删除
     *
     * @param id ids
     */
    @GetMapping("/delete")
    public R delete(@RequestParam("id") Integer id) {
        sysMenuService.delete(id);
        return R.success("删除成功");
    }

    /**
     * 更新
     *
     * @param req sysMenu
     */
    @PostMapping("/update")
    public R update(@RequestBody SysMenuReq req) {
        sysMenuService.updateMenu(req);
        return R.success("更新成功");
    }

    /**
     * 详情
     *
     * @param id id
     * @return SysMenu
     */
    @GetMapping("/detail")
    public R detail(@RequestParam("id") Integer id) {
        return R.success(sysMenuService.getById(id));
    }

    /**
     * 菜单列表(递归遍历所有菜单)
     *
     * @return IPage<SysMenu>
     */
    @GetMapping("/list")
    public R list(Integer id, String menuName) {
        List<SysMenuListVo> list = sysMenuService.getList(id, menuName);
        return R.success(list);
    }

}